package com.flycun.quickstart.web;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.flycun.quickstart.mapper.CustomerMapper;
import com.flycun.quickstart.model.Customer;

@RestController
public class CustomerController {
	
	Logger logger=LoggerFactory.getLogger(CustomerController.class);
	
	@Autowired
	private CustomerMapper customerMapper;
	
	@RequestMapping("/getUsers")
	public List<Customer> getUsers() {
		List<Customer> users=customerMapper.getAll();
		return users;
	}
	
    @RequestMapping("/getUser")
    public Customer getUser(Long id) {
    	Customer user=customerMapper.getOne(id);
        return user;
    }
    
    @RequestMapping("/add")
    public void save(Customer user) {
    	logger.info("save user before:{}",user);
    	customerMapper.insert(user);
    	logger.info("save user after:{}",user);
    }
    
    @RequestMapping(value="update")
    public void update(Customer user) {
    	customerMapper.update(user);
    }
    
    @RequestMapping(value="/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
    	customerMapper.delete(id);
    }
    
    
}